package com.ck.ips.controller.sys;

import com.alibaba.fastjson.JSONArray;
import com.ck.common.model.OperationResult;
import com.ck.common.model.Sysconfig;
import com.ck.core.annotation.LoginRequired;
import com.ck.core.annotation.ResourcePermissionRequired;
import com.ck.core.annotation.SysLog;
import com.ck.core.constant.ModuleConstant;
import com.ck.ips.controller.BaseController;
import com.ck.ips.service.sys.SysConfigService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
* @Description: 系统配置controller
* @Author: hf
* @Date:    2019/5/7 11:32
* @Version: 1.0
*/
@LoginRequired
@RestController
@RequestMapping("/sysconfig")
public class SysConfigController extends BaseController {
	private static Logger logger = LoggerFactory.getLogger(SysConfigController.class);
	@Autowired
	private SysConfigService sysConfigService;

	/**
	 * 获取所有系统配置
	 */
	@PostMapping(value = "/list")
	public Object getAllConfig() {
		return sysConfigService.getAllConfig();
	}

	/**
	 * 修改系统配置
	 */
	@SysLog(module = ModuleConstant.MODULE_SYSTEM)
	@ResourcePermissionRequired
	@PostMapping(value = "/update")
	public OperationResult update(String type, String value) {
		Sysconfig sysconfig = new Sysconfig(type,value);
		return sysConfigService.updateConfig(sysconfig);
	}

	/**
	 * 修改系统配置（批量）
	 */
	@SysLog(module = ModuleConstant.MODULE_SYSTEM)
	@ResourcePermissionRequired
	@PostMapping(value = "/batchupdate")
	public OperationResult batchUpdate(String configs) {
		List<Sysconfig> configList = JSONArray.parseArray(configs, Sysconfig.class);
		return sysConfigService.batchUpdate(configList);
	}

}
